﻿using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;

namespace PLCWpfTest.Converters
{
    public class BooleanToSolidColorBrushConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                throw new ArgumentNullException("Value can not be null");
            }
            Color color = (bool)value ? Colors.Green : Colors.Red;
            SolidColorBrush solidColorBrush = new SolidColorBrush(color);
            return solidColorBrush;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                throw new ArgumentNullException("Value can not be null");
            }
            SolidColorBrush solidColorBrush = (SolidColorBrush)value;
            bool rs = solidColorBrush.Color == Colors.Green;
            return rs;
        }
    }
}
